<%@ tag pageEncoding="UTF-8" import="java.util.*,com.jiepos.mpos.common.constant.SystemConstant,org.springframework.data.redis.core.*,org.springframework.web.context.support.WebApplicationContextUtils,org.springframework.web.context.WebApplicationContext"%>

<%@ attribute name="id" type="java.lang.String" required="true"  %>
<%@ attribute name="name" type="java.lang.String" required="true"  %>
<%@ attribute name="code_type" type="java.lang.String" required="true"  %>
<%@ attribute name="selectId" type="java.lang.String" required="false"  %>
<%@ attribute name="types" type="java.lang.String" required="false"  %>
<%@ attribute name="showSelect" type="java.lang.Boolean" required="false"  %>
<%@ attribute name="disabled" type="java.lang.Boolean" required="false" %>

<%if(this.types != null && this.types.equals("list")){ 
	 %>
	<input editable="false"  class="easyui-combobox" name="${name}" id="${id}"   >
	<%}else{ 
	%>
	<input editable="false"  class="easyui-combobox" name="${name}" id="${id}"  >

	<%} %>
<%
WebApplicationContext wac = WebApplicationContextUtils.getWebApplicationContext(((PageContext)this.getJspContext()).getServletContext());
RedisTemplate redisTemplate = (RedisTemplate)wac.getBean("redisTemplate");
HashOperations<String, Object, Object>  hash = redisTemplate.opsForHash();

Map codeMap = (Map)hash.entries(SystemConstant.CACHE_CODELIST);
List<Map<String, String>> list = (ArrayList)codeMap.get(this.code_type.toUpperCase());

Collections.sort(list, new Comparator<Map<String, String>>() {
    public int compare(Map<String, String> o1, Map<String, String> o2) {
        return o1.get("code_val").compareTo(o2.get("code_val"));
    }
});%>
<script>
$('#${id}').combobox({      
	data:[
 
<%
Map dataMap = null;
if(this.showSelect != null && this.showSelect){
%>
 	{ "id": "", "text": "--请选择--","selected":true },
<%
}
if(list != null){
	for(int i= 0 ;i  < list.size();i++){
		dataMap = list.get(i);
		if(selectId != null && !"".equals(selectId) && selectId.equals(dataMap.get("code_val"))){
%>
		 	{ "id": "<%=dataMap.get("code_val")%>", "text": "<%=dataMap.get("code_val")%>-<%=String.valueOf(dataMap.get("code_desc")).trim() %>","selected":true },
<%		} else{ 
			if((selectId == null ||"".equals(selectId) ) && i==0 && (this.showSelect == null || !this.showSelect)){			
%>
				{ "id": "<%=dataMap.get("code_val")%>", "text": "<%=dataMap.get("code_val")%>-<%=String.valueOf(dataMap.get("code_desc")).trim() %>" ,"selected":true },
<%          } else{
%>
				{ "id": "<%=dataMap.get("code_val")%>", "text": "<%=dataMap.get("code_val")%>-<%=String.valueOf(dataMap.get("code_desc")).trim() %>"},
<%		
            }
		}
	}
}%> 
 
    ],
    valueField:'id',
    textField:'text',
    panelHeight:'auto',
    editable:false
 }); 
 
<%if(this.disabled != null && this.disabled){%> 
	document.getElementById("${id}").disabled="disabled";
	$("#${id}").combobox({disabled: true}); 	
	$('#${id}').combobox({      
	    editable:false  //是否可编辑
	});  
<%}%>
</script>

